
print("Start document")


module("Db", package.seeall )

DocumentList = {}

DOCUMENT = DOCUMENT or {}
DOCUMENTMeta = DOCUMENTMeta or {
	__index = DOCUMENT
}

function NewDocument( name )
	
	local o = {
		name = name
	}
	
	setmetatable( o, DOCUMENTMeta )
	
	table.insert( DocumentList, o )
	
	return o

end




DOCUMENT.name = nil

/**
	Called when a new player joins the game
*/
function DOCUMENT:NewPlayer( ply )
	error("Not implemented new player on ("..tostring(self.Document)..")")
end

/**
	Called when with available data for this object has loaded
*/
function DOCUMENT:LoadPlayer( ply, data )
	error("Not implemented load player on ("..tostring(self.Document)..")")
end

/**
	Get the modifier operation to be applied on this user
*/
function DOCUMENT:SavePlayer( ply )
	return { 
		[self.name] = self:GetData( ply ) 
	}
end

function DOCUMENT:GetData( ply )
	error("Not implemented save player on ("..tostring(self.Document)..")")
end


/**
	Saves this unique object
*/
function DOCUMENT:Save( ply )
	
	if !ply.Db then
		error("Player db is not yet loaded")
	end
	
	ply.Db:SaveRequest( self:SavePlayer( ply ) )
	
end